package com.pan.controller;

import com.pan.cache.PersonCache;
import com.pan.dto.Person;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/person")
public class PersonController {

    @Autowired
    PersonCache personCache;
    @Autowired
    ApplicationContext applicationContext;

    @GetMapping("/id")
    public String getPerson(String userId){

        return personCache.getPerson(userId);
    }

    @GetMapping("/value")
    public Person getPersonValue(String userId){

        return personCache.getPersonValue(userId);
    }

    @GetMapping("/printCurrentBean")
    public void printCurrentBean(){

        PersonController bean = applicationContext.getBean(PersonController.class);
        log.info(bean.getClass().getName());
        this.innerInvoke();
    }

    @GetMapping("/inner")
    public void innerInvoke(){

        log.info(this.getClass().getTypeName());
    }
}
